package com.example.xinli.service.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.xinli.dao.SanjianxiaoshiMapper;
import com.example.xinli.dao.YingduijihuaMapper;
import com.example.xinli.domain.entity.Sanjianxiaoshi;
import com.example.xinli.domain.entity.Yingduijihua;
import com.example.xinli.domain.vo.ResponseBean;
import com.example.xinli.domain.vo.ResponseBeanEnum;
import com.example.xinli.domain.vo.SanjianSubmitVo;
import com.example.xinli.domain.vo.YingduijihuaSubmitVo;
import com.example.xinli.service.ISanjianxiaoshiService;
import com.example.xinli.service.IYingduijihuaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class SanjianxiaoshiServiceImpl extends ServiceImpl<SanjianxiaoshiMapper, Sanjianxiaoshi> implements ISanjianxiaoshiService {

    @Autowired
    SanjianxiaoshiMapper sanjianxiaoshiMapper;

    @Override
    public ResponseBean getAllUserSanjianxiaoshi(String userId) {
        QueryWrapper<Sanjianxiaoshi> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        List<Sanjianxiaoshi> sanjianxiaoshiList = sanjianxiaoshiMapper.selectList(queryWrapper);
        return ResponseBean.success(sanjianxiaoshiList);
    }

    @Override
    public ResponseBean submitSanjianxiaoshi(SanjianSubmitVo sanjianSubmitVo) {
        Sanjianxiaoshi sanjianxiaoshi = new Sanjianxiaoshi();
        sanjianxiaoshi.setUserId(sanjianSubmitVo.getUserId());
        sanjianxiaoshi.setSanjianName(sanjianSubmitVo.getName());
        sanjianxiaoshi.setDate(sanjianSubmitVo.getDate());
        sanjianxiaoshi.setStatusUrl(sanjianSubmitVo.getStatusUrl());
        sanjianxiaoshi.setOne(sanjianSubmitVo.getOne());
        sanjianxiaoshi.setTwo(sanjianSubmitVo.getTwo());
        sanjianxiaoshi.setThree(sanjianSubmitVo.getThree());

        int res = sanjianxiaoshiMapper.insert(sanjianxiaoshi);
        if (res > 0) {
            return ResponseBean.success();
        }
        return ResponseBean.error(ResponseBeanEnum.ERROR);
    }
}

